﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace WebApplication1
{
    class DataBase
    {
        
           public static bool VnesiModel(String MarkaSifra, String Proizvoditel, String Model, String Tip, String Informacii, String Slika, String WebModeli)
                {
                    MySqlConnection con = new MySqlConnection();
                    con.ConnectionString = ConfigurationManager.ConnectionStrings["MojaKonekcija"].ConnectionString;
                   // MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=avtomobili;password=ace;");
                    MySqlCommand cmd = new MySqlCommand("INSERT INTO modeli(MarkaSifra, Proizvoditel, Model, Tip, Informacii, Slika, WebModeli) VALUES(@MarkaSifra,@Proizvoditel,@Model,@Tip,@Informacii,@Slika,@WebModeli)", con);

                    cmd.Parameters.AddWithValue("@MarkaSifra", MarkaSifra);
                    cmd.Parameters.AddWithValue("@Proizvoditel", Proizvoditel);
                    cmd.Parameters.AddWithValue("@Model", Model);
                    cmd.Parameters.AddWithValue("@Tip", Tip);
                    cmd.Parameters.AddWithValue("@Informacii", Informacii);
                    cmd.Parameters.AddWithValue("@Slika", Slika);
                    cmd.Parameters.AddWithValue("@WebModeli", WebModeli);

                    MySqlDataReader rd = null;
            
                    try
                    {
                        con.Open();
                        rd = cmd.ExecuteReader();
                        rd.Close();
                    }
                    catch (MySqlException ex)
                    {
                     //   MessageBox.Show(ex.Message);
                        return false;
                    }
                    finally
                    {
                        con.Close();
                    }
                    return true;
                }

           public static bool VnesiProizvoditel(String ImeProizvoditel, String Logo, String WebProizvoditeli)
        {
            MySqlConnection con = new MySqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["MojaKonekcija"].ConnectionString;
            // MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=avtomobili;password=ace;");
            MySqlCommand cmd = new MySqlCommand("INSERT INTO proizvoditeli(ImeProizvoditel, Logo, WebProizvoditeli) VALUES(@ImeProizvoditel,@Logo,@WebProizvoditeli)", con);

            cmd.Parameters.AddWithValue("@ImeProizvoditel", ImeProizvoditel);
            cmd.Parameters.AddWithValue("@Logo", Logo);
            cmd.Parameters.AddWithValue("@WebProizvoditeli", WebProizvoditeli);

            MySqlDataReader rd = null;
            
            try
            {
                con.Open();
                rd = cmd.ExecuteReader();
                rd.Close();
            }
            catch (MySqlException ex)
            {
             //   MessageBox.Show(ex.Message);
                return false;
            }
            finally
            {
                con.Close();
            }
            return true;
        }

           public static bool VnesiMotor(String Model, String Motor, String SilaKS, String Gorivo, String Zafatnina, String Potrosuvacka, String CenaEvra)
        {
            MySqlConnection con = new MySqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["MojaKonekcija"].ConnectionString;
            // MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=avtomobili;password=ace;");
            MySqlCommand cmd = new MySqlCommand("INSERT INTO motori(Model, Motor, SilaKS, Gorivo, Zafatnina, Potrosuvacka, CenaEvra) VALUES(@Model,@Motor,@SilaKS,@Gorivo,@Zafatnina,@Potrosuvacka,@CenaEvra)", con);

            cmd.Parameters.AddWithValue("@Model", Model);
            cmd.Parameters.AddWithValue("@Motor", Motor);
            cmd.Parameters.AddWithValue("@SilaKS", SilaKS);
            cmd.Parameters.AddWithValue("@Gorivo", Gorivo);
            cmd.Parameters.AddWithValue("@Zafatnina", Zafatnina);
            cmd.Parameters.AddWithValue("@Potrosuvacka", Potrosuvacka);
            cmd.Parameters.AddWithValue("@CenaEvra", CenaEvra);

            MySqlDataReader rd = null;
            
            try
            {
                con.Open();
                rd = cmd.ExecuteReader();
                rd.Close();
            }
            catch (MySqlException ex)
            {
             //   MessageBox.Show(ex.Message);
                return false;
            }
            finally
            {
                con.Close();
            }
            return true;
        } 
         
        public static bool VnesiSlika(String Model, String SlikaGalerija)
        {
            MySqlConnection con = new MySqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["MojaKonekcija"].ConnectionString;
            // MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=avtomobili;password=ace;");
            MySqlCommand cmd = new MySqlCommand("INSERT INTO galerija(Model, SlikaGalerija) VALUES(@Model,@SlikaGalerija)", con);

            cmd.Parameters.AddWithValue("@Model", Model);
            cmd.Parameters.AddWithValue("@SlikaGalerija", SlikaGalerija);

            MySqlDataReader rd = null;
            
            try
            {
                con.Open();
                rd = cmd.ExecuteReader();
                rd.Close();
            }
            catch (MySqlException ex)
            {
             //   MessageBox.Show(ex.Message);
                return false;
            }
            finally
            {
                con.Close();
            }
            return true;
        }
          
          public static bool IzbrisiModel(String Broj)
                {
                    MySqlConnection con = new MySqlConnection();
                    con.ConnectionString = ConfigurationManager.ConnectionStrings["MojaKonekcija"].ConnectionString;
                    // MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=avtomobili;password=ace;");
                    MySqlCommand cmd = new MySqlCommand("DELETE FROM modeli WHERE Broj=@Broj", con);
            
                    cmd.Parameters.AddWithValue("@Broj", Broj);

                    MySqlDataReader rd = null;
            
                    try
                    {
                        con.Open();
                        rd = cmd.ExecuteReader();
                        rd.Close();
                    }
                    catch (MySqlException ex)
                    {
                     //   MessageBox.Show(ex.Message);
                        return false;
                    }
                    finally
                    {
                        con.Close();
                    }
                    return true;
                } 
         
          public static bool IzbrisiMotor(String Broj)
                {
                    MySqlConnection con = new MySqlConnection();
                    con.ConnectionString = ConfigurationManager.ConnectionStrings["MojaKonekcija"].ConnectionString;
                    // MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=avtomobili;password=ace;");
                    MySqlCommand cmd = new MySqlCommand("DELETE FROM motori WHERE Broj=@Broj", con);
            
                    cmd.Parameters.AddWithValue("@Broj", Broj);

                    MySqlDataReader rd = null;
            
                    try
                    {
                        con.Open();
                        rd = cmd.ExecuteReader();
                        rd.Close();
                    }
                    catch (MySqlException ex)
                    {
                     //   MessageBox.Show(ex.Message);
                        return false;
                    }
                    finally
                    {
                        con.Close();
                    }
                    return true;
                }
          
          public static bool IzbrisiProizvoditel(String Broj)
                {
                    MySqlConnection con = new MySqlConnection();
                    con.ConnectionString = ConfigurationManager.ConnectionStrings["MojaKonekcija"].ConnectionString;
                    // MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=avtomobili;password=ace;");
                    MySqlCommand cmd = new MySqlCommand("DELETE FROM proizvoditeli WHERE Broj=@Broj", con);
            
                    cmd.Parameters.AddWithValue("@Broj", Broj);

                    MySqlDataReader rd = null;
            
                    try
                    {
                        con.Open();
                        rd = cmd.ExecuteReader();
                        rd.Close();
                    }
                    catch (MySqlException ex)
                    {
                     //   MessageBox.Show(ex.Message);
                        return false;
                    }
                    finally
                    {
                        con.Close();
                    }
                    return true;
                }
          
          public static bool IzbrisiSlika(String Broj)
                {
                    MySqlConnection con = new MySqlConnection();
                    con.ConnectionString = ConfigurationManager.ConnectionStrings["MojaKonekcija"].ConnectionString;
                    // MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=avtomobili;password=ace;");
                    MySqlCommand cmd = new MySqlCommand("DELETE FROM galerija WHERE Broj=@Broj", con);
            
                    cmd.Parameters.AddWithValue("@Broj", Broj);

                    MySqlDataReader rd = null;
            
                    try
                    {
                        con.Open();
                        rd = cmd.ExecuteReader();
                        rd.Close();
                    }
                    catch (MySqlException ex)
                    {
                     //   MessageBox.Show(ex.Message);
                        return false;
                    }
                    finally
                    {
                        con.Close();
                    }
                    return true;
                }

          public static bool AzurirajModel(String Broj, String MarkaSifra, String Proizvoditel, String Model, String Tip, String Informacii, String Slika, String WebModeli)
                {
                    MySqlConnection con = new MySqlConnection();
                    con.ConnectionString = ConfigurationManager.ConnectionStrings["MojaKonekcija"].ConnectionString;
                    // MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=avtomobili;password=ace;");
                    MySqlCommand cmd = new MySqlCommand("UPDATE modeli SET MarkaSifra=@MarkaSifra, Proizvoditel=@Proizvoditel, Model=@Model, Tip=@Tip, Informacii=@Informacii, Slika=@Slika, WebModeli=@WebModeli WHERE Broj=@Broj", con);
                    MySqlDataReader rd = null;

                    cmd.Parameters.AddWithValue("@Broj", Broj);
                    cmd.Parameters.AddWithValue("@MarkaSifra", MarkaSifra);
                    cmd.Parameters.AddWithValue("@Proizvoditel", Proizvoditel);
                    cmd.Parameters.AddWithValue("@Model", Model);
                    cmd.Parameters.AddWithValue("@Tip", Tip);
                    cmd.Parameters.AddWithValue("@Informacii", Informacii);
                    cmd.Parameters.AddWithValue("@Slika", Slika);
                    cmd.Parameters.AddWithValue("@WebModeli", WebModeli);

                    try
                    {
                        con.Open();
                        rd = cmd.ExecuteReader();
                        rd.Close();
                    }
                    catch (MySqlException ex)
                    {
                     //   MessageBox.Show(ex.Message);
                        return false;
                    }
                    finally
                    {
                        con.Close();

                    }
                    return true;
                }

          public static bool AzurirajMotor(String Broj, String Model, String Motor, String SilaKS, String Gorivo, String Zafatnina, String Potrosuvacka, String CenaEvra)
                {
                    MySqlConnection con = new MySqlConnection();
                    con.ConnectionString = ConfigurationManager.ConnectionStrings["MojaKonekcija"].ConnectionString;
                    // MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=avtomobili;password=ace;");
                    MySqlCommand cmd = new MySqlCommand("UPDATE motori SET Model=@Model, Motor=@Motor, SilaKS=@SilaKS, Gorivo=@Gorivo, Zafatnina=@Zafatnina, Potrosuvacka=@Potrosuvacka, CenaEvra=@CenaEvra WHERE Broj=@Broj", con);
                    MySqlDataReader rd = null;

                    cmd.Parameters.AddWithValue("@Broj", Broj);
                    cmd.Parameters.AddWithValue("@Model", Model);
                    cmd.Parameters.AddWithValue("@Motor", Motor);
                    cmd.Parameters.AddWithValue("@SilaKS", SilaKS);
                    cmd.Parameters.AddWithValue("@Gorivo", Gorivo);
                    cmd.Parameters.AddWithValue("@Zafatnina", Zafatnina);
                    cmd.Parameters.AddWithValue("@Potrosuvacka", Potrosuvacka);
                    cmd.Parameters.AddWithValue("@CenaEvra", CenaEvra);

                    try
                    {
                        con.Open();
                        rd = cmd.ExecuteReader();
                        rd.Close();
                    }
                    catch (MySqlException ex)
                    {
                     //   MessageBox.Show(ex.Message);
                        return false;
                    }
                    finally
                    {
                        con.Close();

                    }
                    return true;
                }

          public static bool AzurirajProizvoditel(String Broj, String ImeProizvoditel, String Logo, String WebProizvoditeli)
                {
                    MySqlConnection con = new MySqlConnection();
                    con.ConnectionString = ConfigurationManager.ConnectionStrings["MojaKonekcija"].ConnectionString;
                    // MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=avtomobili;password=ace;");
                    MySqlCommand cmd = new MySqlCommand("UPDATE proizvoditeli SET ImeProizvoditel=@ImeProizvoditel, Logo=@Logo, WebProizvoditeli=@WebProizvoditeli WHERE Broj=@Broj", con);
                    MySqlDataReader rd = null;

                    cmd.Parameters.AddWithValue("@Broj", Broj);
                    cmd.Parameters.AddWithValue("@ImeProizvoditel", ImeProizvoditel);
                    cmd.Parameters.AddWithValue("@Logo", Logo);
                    cmd.Parameters.AddWithValue("@WebProizvoditeli", WebProizvoditeli);

                    try
                    {
                        con.Open();
                        rd = cmd.ExecuteReader();
                        rd.Close();
                    }
                    catch (MySqlException ex)
                    {
                     //   MessageBox.Show(ex.Message);
                        return false;
                    }
                    finally
                    {
                        con.Close();

                    }
                    return true;
                }

          public static bool AzurirajSlika(String Broj, String Model, String SlikaGalerija)
                {
                    MySqlConnection con = new MySqlConnection();
                    con.ConnectionString = ConfigurationManager.ConnectionStrings["MojaKonekcija"].ConnectionString;
                    // MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=avtomobili;password=ace;");
                    MySqlCommand cmd = new MySqlCommand("UPDATE galerija SET Model=@Model, SlikaGalerija=@SlikaGalerija WHERE Broj=@Broj", con);
                    MySqlDataReader rd = null;

                    cmd.Parameters.AddWithValue("@Broj", Broj);
                    cmd.Parameters.AddWithValue("@Model", Model);
                    cmd.Parameters.AddWithValue("@SlikaGalerija", SlikaGalerija);

                    try
                    {
                        con.Open();
                        rd = cmd.ExecuteReader();
                        rd.Close();
                    }
                    catch (MySqlException ex)
                    {
                     //   MessageBox.Show(ex.Message);
                        return false;
                    }
                    finally
                    {
                        con.Close();

                    }
                    return true;
                }
          
    }
} 